# -*- coding: utf-8 -*-
from django.db import models
from pub.gridfsstorage import MyGridFSStorage

    
class District(models.Model):
    """
            记录省、市、区、镇等信息
    """
    name = models.CharField("地区名称", max_length="50")
    code = models.CharField("地区编号", max_length="10", blank=True)
    parent = models.ForeignKey("self", verbose_name="上一级地区名称", blank=True, null=True)
    
    #地区所在级别
    level = models.PositiveSmallIntegerField(default=1) 
    
    def __unicode__(self):
        return u'%s,%s' %(self.code,self.name)
    
class Bus_area(models.Model):
    """
            商圈,记录每个district里面有哪些商圈,俗称地标。
    """
    name = models.CharField("商圈名称", max_length="50")
    desc = models.TextField("商圈描述", blank=True, null=True)
    #由啊伟处理
    img = models.ImageField(upload_to='/',storage=MyGridFSStorage(database='mongodb'),blank=True,null=True)
    
    #权重越大显示在越前,相当于浏览者的关注度
    weight = models.PositiveSmallIntegerField(default=1)
    district = models.ForeignKey(District, verbose_name="所属地区")
    def __unicode__(self):
        return u'%s' %(self.name)
    

class Cuisine(models.Model):
    """
            菜系
    """
    name = models.CharField("菜系名称", max_length="50")
    desc = models.TextField("菜系描述", blank=True, null=True)
    img = models.ImageField(upload_to='/',storage=MyGridFSStorage(database='mongodb'),blank=True,null=True)

    #权重越大显示在越前,相当于浏览者的关注度
    weight = models.PositiveSmallIntegerField(default=1)
    parent = models.ForeignKey("self", verbose_name="上一级菜系名称", blank=True, null=True)
    
    #菜系所在级别
    level = models.PositiveSmallIntegerField(default=1,null=True) 
    def __unicode__(self):
        return u'%s' %(self.name)
        
    
class Dict(models.Model):
    """
            平台的公共字典
    """
    #类型
    type = models.CharField("类型", max_length="10")
    key = models.CharField(max_length="10")
    value = models.CharField(max_length="50")
    
    #排序权重
    weight = models.PositiveSmallIntegerField(default=1)
    
    def __unicode__(self):
        return u'%s' %(self.value)

    class Meta:
        permissions = (
            ("customer", "消费者权限"),
            ("rest_apply", "消费者申请权限"),
            ("rest", "餐厅权限"),
            ("service", "客服权限"),
        )
        

class Init_data(models.Model):
    name = models.CharField("数据初始化", max_length="50")

